In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import numpy as np
import seaborn as sns
import re
In [2]:
# Loading Google Trends dataset
trends = pd.read_json('GoogleTrends.json')
trends.head() # Certain columns within the dataset are also stored in json format, they will be processed later on
Out[2]:
inputUrlOrTerm searchTerm interestOverTime_timelineData interestOverTime_averages interestBySubregion interestByCity relatedTopics_top relatedTopics_rising relatedQueries_top relatedQueries_rising interestBy
0 Rockstar Games Rockstar Games [{'time': '1561852800', 'formattedTime': 'Jun ... [] [] [] [{'topic': {'mid': '/m/01_4mn', 'title': 'Rock... [{'topic': {'mid': '/g/11tfwwbjts', 'title': '... [{'query': 'rockstar games gta', 'value': 100,... [{'query': 'epic games launcher', 'value': 197... [{'geoCode': 'HU', 'geoName': 'Hungary', 'valu...
1 Grand Theft Auto VI Grand Theft Auto VI [{'time': '1561852800', 'formattedTime': 'Jun ... [] [] [] [{'topic': {'mid': '/m/01_4mn', 'title': 'Rock... [] [{'query': 'gta vi', 'value': 100, 'formattedV... [{'query': 'ps5 games', 'value': 250, 'formatt... [{'geoCode': 'BW', 'geoName': 'Botswana', 'val...
2 Red Dead Redemption 2 Red Dead Redemption 2 [{'time': '1561852800', 'formattedTime': 'Jun ... [] [] [] [{'topic': {'mid': '/m/0hn9j18', 'title': 'Red... [{'topic': {'mid': '/g/11h7t018k5', 'title': '... [{'query': 'red dead redemption 2 pc', 'value'... [{'query': 'rockstar launcher', 'value': 20900... [{'geoCode': 'IS', 'geoName': 'Iceland', 'valu...
3 Grand Theft Auto V Grand Theft Auto V [{'time': '1561852800', 'formattedTime': 'Jun ... [] [] [] [{'topic': {'mid': '/m/04w8jw', 'title': 'Gran... [{'topic': {'mid': '/g/11tfwwbjts', 'title': '... [{'query': 'gta', 'value': 100, 'formattedValu... [{'query': 'grand theft auto v is one of the l... [{'geoCode': 'CG', 'geoName': 'Congo - Brazzav...
In [3]:
trends['relatedQueries_top'][0]
Out[3]:
[{'query': 'rockstar games gta',
  'value': 100,
  'formattedValue': '100',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+games+gta&date=today+5-y'},
 {'query': 'gta',
  'value': 100,
  'formattedValue': '100',
  'hasData': True,
  'link': '/trends/explore?q=gta&date=today+5-y'},
 {'query': 'rockstar social club',
  'value': 48,
  'formattedValue': '48',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+social+club&date=today+5-y'},
 {'query': 'rockstar games club',
  'value': 47,
  'formattedValue': '47',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+games+club&date=today+5-y'},
 {'query': 'rockstar games social',
  'value': 46,
  'formattedValue': '46',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+games+social&date=today+5-y'},
 {'query': 'rockstar launcher',
  'value': 46,
  'formattedValue': '46',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+launcher&date=today+5-y'},
 {'query': 'social club rockstar games',
  'value': 45,
  'formattedValue': '45',
  'hasData': True,
  'link': '/trends/explore?q=social+club+rockstar+games&date=today+5-y'},
 {'query': 'social club',
  'value': 45,
  'formattedValue': '45',
  'hasData': True,
  'link': '/trends/explore?q=social+club&date=today+5-y'},
 {'query': 'rockstar games social club',
  'value': 45,
  'formattedValue': '45',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+games+social+club&date=today+5-y'},
 {'query': 'rockstar games launcher',
  'value': 43,
  'formattedValue': '43',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+games+launcher&date=today+5-y'},
 {'query': 'gta 6',
  'value': 38,
  'formattedValue': '38',
  'hasData': True,
  'link': '/trends/explore?q=gta+6&date=today+5-y'},
 {'query': 'gta 6 rockstar games',
  'value': 37,
  'formattedValue': '37',
  'hasData': True,
  'link': '/trends/explore?q=gta+6+rockstar+games&date=today+5-y'},
 {'query': 'gta 5 rockstar games',
  'value': 26,
  'formattedValue': '26',
  'hasData': True,
  'link': '/trends/explore?q=gta+5+rockstar+games&date=today+5-y'},
 {'query': 'gta 5',
  'value': 26,
  'formattedValue': '26',
  'hasData': True,
  'link': '/trends/explore?q=gta+5&date=today+5-y'},
 {'query': 'rockstar games download',
  'value': 23,
  'formattedValue': '23',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+games+download&date=today+5-y'},
 {'query': 'rockstar download',
  'value': 22,
  'formattedValue': '22',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+download&date=today+5-y'},
 {'query': 'epic',
  'value': 20,
  'formattedValue': '20',
  'hasData': True,
  'link': '/trends/explore?q=epic&date=today+5-y'},
 {'query': 'epic games',
  'value': 20,
  'formattedValue': '20',
  'hasData': True,
  'link': '/trends/explore?q=epic+games&date=today+5-y'},
 {'query': 'rockstar game',
  'value': 17,
  'formattedValue': '17',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+game&date=today+5-y'},
 {'query': 'pc games',
  'value': 15,
  'formattedValue': '15',
  'hasData': True,
  'link': '/trends/explore?q=pc+games&date=today+5-y'},
 {'query': 'online games',
  'value': 14,
  'formattedValue': '14',
  'hasData': True,
  'link': '/trends/explore?q=online+games&date=today+5-y'},
 {'query': 'steam',
  'value': 12,
  'formattedValue': '12',
  'hasData': True,
  'link': '/trends/explore?q=steam&date=today+5-y'},
 {'query': 'gta v',
  'value': 11,
  'formattedValue': '11',
  'hasData': True,
  'link': '/trends/explore?q=gta+v&date=today+5-y'},
 {'query': 'rockstar games gta v',
  'value': 11,
  'formattedValue': '11',
  'hasData': True,
  'link': '/trends/explore?q=rockstar+games+gta+v&date=today+5-y'},
 {'query': 'gta online',
  'value': 10,
  'formattedValue': '10',
  'hasData': True,
  'link': '/trends/explore?q=gta+online&date=today+5-y'}]
In [4]:
rockstarTrends = trends.iloc[0,2]
xAxis = []
yAxis = []
for trend in rockstarTrends:
    xAxis.append(trend['formattedAxisTime'])
    yAxis.append(trend['value'])

rockstargamesplot = pd.DataFrame({
    "Time": [datetime.datetime.strptime(data, '%b %d, %Y') for data in xAxis],
    "Interest": [data[0] for data in yAxis]
})
rockstargamesplot
Out[4]:
Time Interest
0 2019-06-30 8
1 2019-07-07 9
2 2019-07-14 10
3 2019-07-21 14
4 2019-07-28 11
... ... ...
257 2024-06-02 13
258 2024-06-09 11
259 2024-06-16 12
260 2024-06-23 13
261 2024-06-30 14

262 rows × 2 columns

In [5]:
rockstarTrends = trends.iloc[1,2]
xAxis = []
yAxis = []
for trend in rockstarTrends:
    xAxis.append(trend['formattedAxisTime'])
    yAxis.append(trend['value'])

gta6plot = pd.DataFrame({
    "Time": [datetime.datetime.strptime(data, '%b %d, %Y') for data in xAxis],
    "Interest": [data[0] for data in yAxis]
})
gta6plot
Out[5]:
Time Interest
0 2019-06-30 1
1 2019-07-07 3
2 2019-07-14 2
3 2019-07-21 3
4 2019-07-28 1
... ... ...
257 2024-06-02 11
258 2024-06-09 12
259 2024-06-16 12
260 2024-06-23 10
261 2024-06-30 10

262 rows × 2 columns

In [6]:
rockstarTrends = trends.iloc[2,2]
xAxis = []
yAxis = []
for trend in rockstarTrends:
    xAxis.append(trend['formattedAxisTime'])
    yAxis.append(trend['value'])

rdr2plot = pd.DataFrame({
    "Time": [datetime.datetime.strptime(data, '%b %d, %Y') for data in xAxis],
    "Interest": [data[0] for data in yAxis]
})
rdr2plot
Out[6]:
Time Interest
0 2019-06-30 25
1 2019-07-07 26
2 2019-07-14 25
3 2019-07-21 24
4 2019-07-28 25
... ... ...
257 2024-06-02 21
258 2024-06-09 22
259 2024-06-16 20
260 2024-06-23 20
261 2024-06-30 20

262 rows × 2 columns

In [7]:
rockstarTrends = trends.iloc[3,2]
xAxis = []
yAxis = []
for trend in rockstarTrends:
    xAxis.append(trend['formattedAxisTime'])
    yAxis.append(trend['value'])

gta5plot = pd.DataFrame({
    "Time": [datetime.datetime.strptime(data, '%b %d, %Y') for data in xAxis],
    "Interest": [data[0] for data in yAxis]
})
gta5plot
Out[7]:
Time Interest
0 2019-06-30 34
1 2019-07-07 37
2 2019-07-14 36
3 2019-07-21 39
4 2019-07-28 41
... ... ...
257 2024-06-02 15
258 2024-06-09 16
259 2024-06-16 18
260 2024-06-23 19
261 2024-06-30 17

262 rows × 2 columns

In [8]:
figure, axis = plt.subplots(2,2)
figure.set_figwidth(15)
figure.set_figheight(15)

# Rockstar Games
axis[0,0].plot(rockstargamesplot['Time'], rockstargamesplot['Interest'])
axis[0,0].set_title('"RockstarGames"')
axis[0,0].set(ylabel = 'Interest')

# GTA VI 
axis[0,1].plot(gta6plot['Time'], gta6plot['Interest'])
axis[0,1].set_title('"Grand Theft Auto VI"')

# Red Dead Redemption 2 
axis[1,0].plot(rdr2plot['Time'], rdr2plot['Interest'])
axis[1,0].set_title('"Red Dead Redemption 2"')
axis[1,0].set(xlabel = 'Year', ylabel = 'Interest')

# GTA V
axis[1,1].plot(gta5plot['Time'], gta5plot['Interest'])
axis[1,1].set_title('"Grand Theft Auto V"')
axis[1,1].set(xlabel = 'Year')
Out[8]:
[Text(0.5, 0, 'Year')]
In [9]:
len(trends['relatedTopics_top'][0])
Out[9]:
25
In [10]:
rockstarTopics = pd.DataFrame({
    'Top_titles': [topicTitle['topic']['title'] for topicTitle in trends['relatedTopics_top'][0][:15]],
    'Top_value': [value['value'] for value in trends['relatedTopics_top'][0][:15]],
    'Rising_titles': [topicTitle['topic']['title'] for topicTitle in trends['relatedTopics_rising'][0][:15]],
    'Rising_value': [value['value'] for value in trends['relatedTopics_rising'][0][:15]],
})

rockstarTopics
Out[10]:
Top_titles Top_value Rising_titles Rising_value
0 Rockstar Games 100 Grand Theft Auto VI 383750
1 Video game 84 Epic Games 264750
2 Grand Theft Auto 27 Rockstar Games Launcher 96600
3 Rockstar Games Social Club 20 Ubisoft 36250
4 Grand Theft Auto V 15 Electronic Arts 26350
5 Social club 12 unavailable 13950
6 Rockstar Games Launcher 11 Prime Gaming 13700
7 Grand Theft Auto VI 8 FiveM 7450
8 Epic Games 5 Grand Theft Auto: The Trilogy – The Definitive... 6350
9 Steam 3 Epic Games Store 5150
10 Personal computer 3 Eneba 5150
11 Epic Games 3 Epic Games 2100
12 Red Dead 3 Grand Theft Auto: The Trilogy 2000
13 Red Dead Redemption 2 3 PlayStation 5 2000
14 Grand Theft Auto: San Andreas 2 Unlink 1800
In [11]:
# GTA VI not analysed due to a lack of data
rdr2Topics = pd.DataFrame({
    'Top_titles': [topicTitle['topic']['title'] for topicTitle in trends['relatedTopics_top'][2][:24]],
    'Top_value': [value['value'] for value in trends['relatedTopics_top'][2][:24]],
    'Rising_titles': [topicTitle['topic']['title'] for topicTitle in trends['relatedTopics_rising'][2][:24]],
    'Rising_value': [value['value'] for value in trends['relatedTopics_rising'][2][:24]],
})

rdr2Topics
Out[11]:
Top_titles Top_value Rising_titles Rising_value
0 Red Dead 100 Arthur Morgan 73200
1 Red Dead Redemption 2 90 Assassin's Creed Valhalla 22250
2 Video game 9 Grand Theft Auto VI 17500
3 Red Dead Redemption 7 Fitgirl 16750
4 PlayStation 4 5 Epic Games 14200
5 Horse 4 Rockstar Games Launcher 13950
6 Personal computer 3 Saint Denis 13750
7 Xbox 3 PlayStation 5 11400
8 Xbox One 3 Cheat codes 10650
9 Grand Theft Auto 2 HowLongToBeat 5600
10 Cheating in video games 2 Micah Bell 5500
11 PlayStation 5 2 Gun 4000
12 Steam 2 Sadie Adler 3150
13 Grand Theft Auto V 2 Nexus Mods 3050
14 Red Dead Online 2 Call of Duty: Modern Warfare 3050
15 Video game modding 2 Nvidia RTX 2500
16 Weapon 1 Crash 2400
17 Treasure 1 Xbox Series X and Series S 1950
18 Rockstar Games 1 Software cracking 1950
19 Requirement 1 Epic Games 1850
20 Sony PlayStation 1 Ryzen 1800
21 PC game 1 Xbox Game Pass 1450
22 Hunting 1 Video game modding 1250
23 Arthur Morgan 1 PC game 650
In [12]:
gta5Topics = pd.DataFrame({
    'Top_titles': [topicTitle['topic']['title'] for topicTitle in trends['relatedTopics_top'][3][:24]],
    'Top_value': [value['value'] for value in trends['relatedTopics_top'][3][:24]],
    'Rising_titles': [topicTitle['topic']['title'] for topicTitle in trends['relatedTopics_rising'][3][:24]],
    'Rising_value': [value['value'] for value in trends['relatedTopics_rising'][3][:24]],
})

gta5Topics
Out[12]:
Top_titles Top_value Rising_titles Rising_value
0 Grand Theft Auto 100 Grand Theft Auto VI 83900
1 Grand Theft Auto V 97 Epic Games 37150
2 Download 17 Grand Theft Auto: The Trilogy – The Definitive... 21050
3 Video game 12 Premium Edition 14050
4 apk 7 Epic Games Store 9800
5 Cheating in video games 7 Rockstar Games Launcher 8150
6 Android 6 Grand Theft Auto V: The Manual 7400
7 PlayStation 4 6 PlayStation 5 6750
8 Grand Theft Auto: San Andreas 5 Epic Games 5350
9 Xbox 4 Cheat codes 4100
10 Xbox One 4 APKPure 4000
11 Personal computer 4 Xbox Game Pass 2850
12 Grand Theft Auto Online 3 Authentication 2400
13 Grand Theft Auto: Vice City 3 FiveM 1650
14 Grand Theft Auto IV 3 Cyberpunk 2077 1400
15 Video game modding 3 PlayStation Plus 1100
16 Sony PlayStation 2 Cross-platform play 950
17 PlayStation 3 2 PUBG: Battlegrounds 750
18 Trophy 2 Call of Duty: Modern Warfare 750
19 Steam 2 Minecraft 200
20 Cheat codes 2 apk 160
21 Minecraft 2 Android 80
22 Xbox 360 2 Sony PlayStation 70
23 Rockstar Games 2 Rockstar Games 60
In [13]:
rockstarQueries = pd.DataFrame({
    'Top_queries': [topicTitle['query'] for topicTitle in trends['relatedQueries_top'][0][:15]],
    'Top_value': [value['value'] for value in trends['relatedQueries_top'][0][:15]],
    'Rising_queries': [topicTitle['query'] for topicTitle in trends['relatedQueries_rising'][0][:15]],
    'Rising_value': [value['value'] for value in trends['relatedQueries_rising'][0][:15]],
})

rockstarQueries
Out[13]:
Top_queries Top_value Rising_queries Rising_value
0 rockstar games gta 100 epic games launcher 19700
1 gta 100 valorant 14400
2 rockstar social club 48 discord download 11700
3 rockstar games club 47 eneba 7600
4 rockstar games social 46 ubisoft connect 7000
5 rockstar launcher 46 epic games download 5850
6 social club rockstar games 45 rockstar launcher 5800
7 social club 45 rockstar games launcher offline 5750
8 rockstar games social club 45 rockstar games launcher 5500
9 rockstar games launcher 43 rockstar games launcher not working 5400
10 gta 6 38 steamunlocked 4900
11 gta 6 rockstar games 37 rockstar games launcher offline mode 4850
12 gta 5 rockstar games 26 rockstar games gta 6 trailer leak 4750
13 gta 5 26 prime gaming 4400
14 rockstar games download 23 rockstar game launcher 3700
In [14]:
# GTA VI not analysed due to a lack of data
rdr2Queries = pd.DataFrame({
    'Top_queries': [topicTitle['query'] for topicTitle in trends['relatedQueries_top'][2][:15]],
    'Top_value': [value['value'] for value in trends['relatedQueries_top'][2][:15]],
    'Rising_queries': [topicTitle['query'] for topicTitle in trends['relatedQueries_rising'][2][:15]],
    'Rising_value': [value['value'] for value in trends['relatedQueries_rising'][2][:15]],
})

rdr2Queries
Out[14]:
Top_queries Top_value Rising_queries Rising_value
0 red dead redemption 2 pc 100 rockstar launcher 20900
1 red dead redemption pc 97 red dead redemption 2 xbox series x 15600
2 red dead online 77 xbox series x 15250
3 red dead redemption online 76 assassin's creed valhalla 14750
4 red dead redemption 2 online 73 elden ring 13950
5 red dead redemption ps4 64 red dead redemption 2 xbox series s 13400
6 ps4 red dead redemption 2 63 xbox series s 12600
7 ps4 62 red dead redemption 2 ps5 upgrade 9300
8 rdr2 51 eneba 8700
9 xbox red dead redemption 2 44 rockstar games launcher 7450
10 red dead redemption 2 game 36 hogwarts legacy 7200
11 red dead redemption map 32 red dead redemption 2 collector map 7050
12 red dead redemption 2 map 31 red dead redemption 2 ps5 60fps 4600
13 gta 28 red dead redemption 2 steam key 3250
14 red dead redemption 2 steam 25 red dead redemption 2 crackwatch 2550
In [15]:
gta5Queries = pd.DataFrame({
    'Top_queries': [topicTitle['query'] for topicTitle in trends['relatedQueries_top'][3][:15]],
    'Top_value': [value['value'] for value in trends['relatedQueries_top'][3][:15]],
    'Rising_queries': [topicTitle['query'] for topicTitle in trends['relatedQueries_rising'][3][:15]],
    'Rising_value': [value['value'] for value in trends['relatedQueries_rising'][3][:15]],
})

gta5Queries
Out[15]:
Top_queries Top_value Rising_queries Rising_value
0 gta 100 grand theft auto v is one of the latest epic p... 21600
1 grand theft auto gta v 99 grand theft auto v xbox series x 14800
2 gta v 98 valorant 10600
3 grand theft auto v gta v 92 happymod 7100
4 grand theft auto v download 51 epic games grand theft auto v 5300
5 download 50 epic games 5200
6 grand theft auto download 50 epic games store 4550
7 gta 5 45 the social club account specified does not own... 4250
8 apk grand theft auto v 28 grand theft auto v ps5 3800
9 grand theft auto v pc 25 fifa 20 1750
10 games 25 cyberpunk 2077 1500
11 grand theft auto apk 25 grand theft auto v premium edition 950
12 grand theft auto games 25 free fire 750
13 grand theft auto online 25 grand theft auto v download apkpure 550
14 grand theft auto v online 24 fivem 550
In [16]:
import plotly.express as px

rockstargeoplotdf = pd.DataFrame({
    'code': [data['geoCode'] for data in trends['interestBy'][0]],
    'country': [data['geoName'] for data in trends['interestBy'][0]],
    'value': [data['value'][0] for data in trends['interestBy'][0]],
})

fig = px.choropleth(rockstargeoplotdf, locations='country', locationmode='country names', color='value', hover_name='country',
                    projection='natural earth', title='Interest by Country')
fig.show()
In [17]:
gta6geoplotdf = pd.DataFrame({
    'code': [data['geoCode'] for data in trends['interestBy'][1]],
    'country': [data['geoName'] for data in trends['interestBy'][1]],
    'value': [data['value'][0] for data in trends['interestBy'][1]],
})

fig = px.choropleth(gta6geoplotdf, locations='country', locationmode='country names', color='value', hover_name='country',
                    projection='natural earth', title='Interest by Country')
fig.show()
In [18]:
rdr2geoplotdf = pd.DataFrame({
    'code': [data['geoCode'] for data in trends['interestBy'][2]],
    'country': [data['geoName'] for data in trends['interestBy'][2]],
    'value': [data['value'][0] for data in trends['interestBy'][2]],
})

fig = px.choropleth(rdr2geoplotdf, locations='country', locationmode='country names', color='value', hover_name='country',
                    projection='natural earth', title='Interest by Country')
fig.show()
In [19]:
gta5geoplotdf = pd.DataFrame({
    'code': [data['geoCode'] for data in trends['interestBy'][3]],
    'country': [data['geoName'] for data in trends['interestBy'][3]],
    'value': [data['value'][0] for data in trends['interestBy'][3]],
})

fig = px.choropleth(gta5geoplotdf, locations='country', locationmode='country names', color='value', hover_name='country',
                    projection='natural earth', title='Interest by Country')
fig.show()
In [ ]: